/*  GMooc - A Java web application for delivering massive open online courses
*   Copyright (C) 2012 Charles A. Wight
*   
*    This program is free software: you can redistribute it and/or modify
*   it under the terms of the GNU General Public License as published by
*   the Free Software Foundation, either version 3 of the License, or
*   (at your option) any later version.
*
*   This program is distributed in the hope that it will be useful,
*   but WITHOUT ANY WARRANTY; without even the implied warranty of
*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*   GNU General Public License for more details.
*
*   You should have received a copy of the GNU General Public License
*   along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

package org.gmooc;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Calendar;
import java.util.Date;

import javax.persistence.Transient;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.google.appengine.api.users.UserService;
import com.google.appengine.api.users.UserServiceFactory;
import com.googlecode.objectify.Objectify;

@SuppressWarnings("serial")
public class About extends HttpServlet {
	
	@Transient static UserService userService = UserServiceFactory.getUserService();
	Objectify ofy = new DAO().ofy();
	static Date termsUpdated;
	static {
		Calendar termsUpdateDate = Calendar.getInstance();
		termsUpdateDate.set(2012,Calendar.AUGUST,20);  // Current terms & conditions set on 8/20/2012
		termsUpdated = termsUpdateDate.getTime();
	}
	
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws IOException {
		
		response.setContentType("text/html");
		PrintWriter out = response.getWriter();
		
		User user = (User)request.getSession(true).getAttribute("User");
		
		out.println(aboutPage(user));
	}
	
	public void doPost(HttpServletRequest request, HttpServletResponse response)
	throws IOException {
		doGet(request,response);
	}

	String aboutPage(User user) {
		StringBuffer buf = new StringBuffer(Home.header(user));
		buf.append(description);
		buf.append(copyright);
		buf.append(terms);
		return buf.toString() + Home.footer;
	}
	
	public static String description = "<h2>About Gmooc</h2>"
		+ "Gmooc is an open source software project specifically designed for hosting massive open online courses (MOOCs). "
		+ "MOOCs can have 100,000 students or more, so special techniques are required to ensure that<ul>"
		+ "<li>the software can scale to essentially infinite size"
		+ "<li>large amounts of data can be read from and written to the database without collisions"
		+ "<li>students can self-organize into study groups to assist each other"
		+ "<li>only the most severe issues get elevated for attention by the course instructor"
		+ "</ul>"
		+ "You may download a free copy of the software that runs this site from the SVN repository using the command line<br>"
		+ "<i>svn checkout http://gmooc.googlecode.com/svn/trunk/</i>";
	
	public static String copyright = "<a NAME=copyright></a>"
		+ "<h3>Copyright &copy; 2012 Chuck Wight</h3>"
		+ "<a rel='license' href=http://creativecommons.org/licenses/by/3.0/us/>"
		+ "<img alt='Creative Commons License' style='border-width:0' align=left hspace=10 vspace=5 "
		+ "src='http://i.creativecommons.org/l/by/3.0/us/88x31.png'/></a>"
		+ "Except where otherwise noted, the copyright to all content displayed on this site is owned by Chuck Wight, "
		+ "and is licensed freely under a "
		+ "<a href='http://creativecommons.org/licenses/by/3.0/us/'>Creative Commons Attribution 3.0 License</a>. "
		+ "Any use of this content must acknowledge ownership by Chuck Wight and must contain appropriate "
		+ "notice of this CC-BY licence. Permissions beyond the scope of this license may be available by contacting "
		+ "<a href=mailto:admin@gmooc.org>admin@gmooc.org</a><p>"
		+ "<h3>DMCA Notice</h3>"
		+ "Gmooc respects the intellectual property rights of others. If you believe that your copyrighted work "
		+ "has been copied in a way that constitutes copyright infringement and is accessible on this site, you may "
		+ "notify our copyright agent, as set forth in the Digital Millennium Copyright Act of 1998 (DMCA). For your "
		+ "complaint to be valid under the DMCA, you must provide the following information when providing notice of "
		+ "the claimed copyright infringement:<ul>"
		+ "<li>A physical or electronic signature of a person authorized to act on behalf of the copyright owner"
		+ "<li>Identification of the copyrighted work claimed to have been infringed"
		+ "<li>Identification of the material that is claimed to be infringing or to be the subject of the infringing "
		+ "activity and that is to be removed"
		+ "<li>Information reasonably sufficient to permit the service provider to contact the complaining party, such as "
		+ "an address, telephone number, and, if available, an electronic mail address"
		+ "<li>A statement that the complaining party believes in good faith that use of the material in the manner "
		+ "complained of is not authorized by the copyright owner, its agent, or law"
		+ "<li>A statement that the information in the notification is accurate, and that under penalty of perjury, "
		+ "the complaining party is authorized to act on behalf of the owner of an exclusive right that is allegedly infringed"
		+ "</ul>"
		+ "The information above must be sent as a written postal mail or email notification to "
		+ "Gmoog.org DMCA Office, 2568 Redondo Ave, Salt Lake City, UT 84108 USA, admin@gmooc.org<p>"
		+ "WE CAUTION YOU THAT UNDER FEDERAL LAW, IF YOU KNOWINGLY MISREPRESENT THAT ONLINE MATERIAL IS INFRINGING, "
		+ "YOU MAY BE SUBJECT TO HEAVY CIVIL PENALTIES. THESE INCLUDE MONETARY DAMAGES, COURT COSTS, AND ATTORNEYS' "
		+ "FEES INCURRED BY US, BY ANY COPYRIGHT OWNER, OR BY ANY COPYRIGHT OWNER'S LICENSEE THAT IS INJURED AS A "
		+ "RESULT OF OUR RELYING UPON YOUR MISREPRESENTATION. YOU MAY ALSO BE SUBJECT TO CRIMINAL PROSECUTION FOR PERJURY.";

	public static String terms = "<a NAME=terms></a>"
		+ "<h3>Gmooc Terms and Conditions of Use</h3>"
		+ "<UL>"
		+ "<LI>These terms and conditions were last updated on " + About.termsUpdated + "."
		+ "<LI>LIMITED LIABILITY." 
		+ "<UL>"
		+ "<LI>GMOOC.ORG AND ITS OWNERS ARE WITHOUT LIABILITY FOR DAMAGES CAUSED OR ALLEGEDLY CAUSED BY ANY FAILURE "
		+ "OF PERFORMANCE, ERROR, OMISSION, INTERRUPTION, DELETION, DEFECT, VIRUS, DELAY IN OPERATION OR "
		+ "TRANSMISSION, INACCURATE INFORMATION, COMMUNICATIONS LINE FAILURE, THEFT OR DESTRUCTION OF OR "
		+ "UNAUTHORIZED ACCESS TO, ALTERATION OF, OR USE OF RECORDS, WHETHER FOR BREACH OF CONTRACT, "
		+ "TORTUOUS BEHAVIOR, NEGLIGENCE, OR UNDER ANY OTHER CAUSE OF ACTION.</LI>"
		+ "</UL>"
		+ "<LI>PRIVACY POLICY.<br>"
		+ "We protect your privacy to the maximum extent that allows the site to function as designed.<br>"
		+ "We will not sell or share any personally identifiable information about our users, except to the "
		+ "extent that users share this information about themselves on this web site through discussion posts and the like. "
		+ "Users may use the <a href='/profile'>Profile</a> page when signed in to change the way that their name is listed, "
		+ "and they may use the site anonymously, so that other users cannot view their name or email address."
		+ "<LI>YOUR ACCEPTANCE OF THESE TERMS<br>"
		+ "By using this Site, you signify your acceptance of this policy and terms of service. "
		+ "If you do not agree to this policy, please do not use our Site. "
		+ "Your continued use of the Site following the posting of changes to this policy will be deemed your acceptance of those changes."
		+ "<LI>CONTACTING US<br>"
		+ "If you have any questions about these Terms and Conditions, our Privacy Policy, the practices of this site, or your dealings with this site, please contact us at:<br>"
		+ "Gmooc.org, 2568 Redondo Ave, Salt Lake City, UT 84108 USA<br>"
		+ "Phone: +1 (801)810-4401<br>"
		+ "Email: <a href=mailto:admin@gmooc.org>admin@gmooc.org</a>"
		+ "</UL>";
}
